package hust.music.action;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;

import hust.music.action.base.ActionBase;
import hust.music.entity.User;
import hust.music.service.UserModService;

/**
 * LoginAjaxAction
 * 
 * @author Txazo
 * @since 1.0
 */
@Controller
@Scope("session")
public class LoginAjaxAction extends ActionBase {

	private static final long serialVersionUID = 1L;

	/** 用户名 */
	private String username;
	/** 密码 */
	private String password;
	/** 是否登录成功 */
	private int flag;

	@Autowired
	private UserModService userModService;

	/**
	 * 用户主页登录
	 * 
	 * @return 逻辑视图
	 */
	public String login() {
		User user = new User();
		user.setUsername(username);
		user.setAuthtoken(password);
		User login = userModService.login(user);
		if (login != null) {
			session.put("user", login);
			flag = 1;
		} else {
			flag = 0;
		}

		return SUCCESS;
	}

	public String getUsername() {
		return username;
	}

	public void setUsername(String username) {
		this.username = username;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public int getFlag() {
		return flag;
	}

	public void setFlag(int flag) {
		this.flag = flag;
	}

}
